package com.gsk.europepharma.salesReport.utils;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * Recuperation de variables de session utiles pour un affichage dans la carto.
 */
public class LibNiveauCarto extends Action {
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		// Recuperation en session 
		
		HttpSession sessionObject = request.getSession();
		
		String libGeogCartoR = (String) sessionObject.getAttribute("libGeogCartoR");
		String pmGeogCartoR = (String) sessionObject.getAttribute("pmGeogCartoR");
		String deltapmGeogCartoR = (String) sessionObject.getAttribute("deltapmGeogCartoR");
		String volGeogCartoR = (String) sessionObject.getAttribute("volGeogCartoR");
		String deltavolGeogCartoR = (String) sessionObject.getAttribute("deltavolGeogCartoR");
		String evolGeogCartoR = (String) sessionObject.getAttribute("evolGeogCartoR");
		String nivGeogCartoR = (String) sessionObject.getAttribute("nivGeogCartoR");
		String idGeogCartoR = (String) sessionObject.getAttribute("idGeogCartoR");
		
		String libGeogCartoS = (String) sessionObject.getAttribute("libGeogCartoS");
		String pmGeogCartoS = (String) sessionObject.getAttribute("pmGeogCartoS");
		String deltapmGeogCartoS = (String) sessionObject.getAttribute("deltapmGeogCartoS");
		String volGeogCartoS = (String) sessionObject.getAttribute("volGeogCartoS");
		String deltavolGeogCartoS = (String) sessionObject.getAttribute("deltavolGeogCartoS");
		String evolGeogCartoS = (String) sessionObject.getAttribute("evolGeogCartoS");
		String nivGeogCartoS = (String) sessionObject.getAttribute("nivGeogCartoS");
		String idGeogCartoS = (String) sessionObject.getAttribute("idGeogCartoS");
		
		HashMap<String, String> hm = new HashMap<String, String>();
		
		hm.put("libGeogCartoR", libGeogCartoR);
		hm.put("pmGeogCartoR", pmGeogCartoR);
		hm.put("deltapmGeogCartoR", deltapmGeogCartoR);
		hm.put("volGeogCartoR", volGeogCartoR);
		hm.put("deltavolGeogCartoR", deltavolGeogCartoR);
		hm.put("evolGeogCartoR", evolGeogCartoR);
		hm.put("nivGeogCartoR", nivGeogCartoR);
		hm.put("idGeogCartoR", idGeogCartoR);
		
		hm.put("libGeogCartoS", libGeogCartoS);
		hm.put("pmGeogCartoS", pmGeogCartoS);
		hm.put("deltapmGeogCartoS", deltapmGeogCartoS);
		hm.put("volGeogCartoS", volGeogCartoS);
		hm.put("deltavolGeogCartoS", deltavolGeogCartoS);
		hm.put("evolGeogCartoS", evolGeogCartoS);
		hm.put("nivGeogCartoS", nivGeogCartoS);
		hm.put("idGeogCartoS", idGeogCartoS);
		
		JSONObject json = JSONObject.fromObject(hm);

		response.addHeader("Content-Type", "application/json");
        response.getOutputStream().write(json.toString().getBytes("UTF-8"));
        response.getOutputStream().flush();

		return null;
	}

}
